package com.zygh.policeasset.controller;

import com.github.pagehelper.util.StringUtil;
import com.zygh.policeasset.component.CommonResult;
import com.zygh.policeasset.pojo.AssetsApprovalSteps;
import com.zygh.policeasset.service.AssetsApprovalStepsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = {"审批步骤配置表"})
@RequestMapping({"/assetsapprovalsteps"})
@RestController
/* loaded from: police-asset-2.0-0.0.1-SNAPSHOT.jar:BOOT-INF/classes/com/zygh/policeasset/controller/AssetsApprovalStepsController.class */
public class AssetsApprovalStepsController {
    @Autowired
    AssetsApprovalStepsService assetsApprovalStepsService;

    @RequestMapping(value = {"/add"}, method = {RequestMethod.POST})
    @ApiOperation("添加审批步骤配置")
    public Object add(@RequestBody List<AssetsApprovalSteps> assetsApprovalSteps) {
        System.out.println(assetsApprovalSteps);
        if (this.assetsApprovalStepsService.findByStepsType(assetsApprovalSteps.get(0).getStepsType()).size() > 0) {
            return new CommonResult().validateFailed("该类别已有审批流程");
        }
        int count = 0;
        for (int i = 0; i < assetsApprovalSteps.size(); i++) {
            count = this.assetsApprovalStepsService.insert(assetsApprovalSteps.get(i));
        }
        if (count > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("添加失败");
    }

    @RequestMapping(value = {"/delete"}, method = {RequestMethod.GET})
    @ApiOperation("删除审批步骤配置")
    public Object delete(@RequestParam String stepType) {
        if (StringUtil.isEmpty(stepType)) {
            return new CommonResult().validateFailed("审批流程类别不能为空");
        }
        if (this.assetsApprovalStepsService.deleteByStepType(stepType) > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("删除失败");
    }

    @RequestMapping(value = {"/update"}, method = {RequestMethod.POST})
    @ApiOperation("修改审批步骤配置")
    public Object update(@RequestBody List<AssetsApprovalSteps> assetsApprovalSteps) {
        if (this.assetsApprovalStepsService.deleteByStepType(assetsApprovalSteps.get(0).getStepsType()) < 0) {
            return new CommonResult().validateFailed("原审批流程清除失败");
        }
        int count1 = 0;
        for (int i = 0; i < assetsApprovalSteps.size(); i++) {
            count1 = this.assetsApprovalStepsService.insert(assetsApprovalSteps.get(i));
        }
        if (count1 > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("修改失败");
    }

    @RequestMapping(value = {"/selectbyid"}, method = {RequestMethod.GET})
    @ApiOperation("单条审批步骤配置查询")
    public Object selectById(@RequestParam Integer id) {
        if (StringUtil.isEmpty(String.valueOf(id))) {
            return new CommonResult().validateFailed("审批步骤配置主键不能为空");
        }
        return new CommonResult().success(this.assetsApprovalStepsService.findById(id));
    }

    @RequestMapping(value = {"/findall"}, method = {RequestMethod.GET})
    @ApiOperation("查询审批步骤配置")
    public Object findAll() {
        return new CommonResult().success(this.assetsApprovalStepsService.findAll());
    }

    @RequestMapping(value = {"/findbycondition"}, method = {RequestMethod.GET})
    @ApiOperation("按流程类别查询")
    public Object findByCondition(@RequestParam String stepsType, @RequestParam(defaultValue = "1", value = "pageNum") int pageNum, @RequestParam(defaultValue = "10", value = "pageSize") int pageSize) {
        return this.assetsApprovalStepsService.findByCondition(stepsType, pageNum, pageSize);
    }
}